﻿using Microsoft.Extensions.Hosting;
using System.Reflection;

namespace CKS.AGV.Core
{
    public class TaskSchedulerServer
    {


        public static void Start()
        {
           var assembly = Assembly.GetExecutingAssembly();
           var jobs = assembly.GetTypes().Where(a=>a.GetCustomAttribute<ScheduleAttribute>() != null).ToArray();

            Parallel.ForEach(jobs,(a) => {

                IHostedService service = (IHostedService)Activator.CreateInstance(a);
                service.StartAsync(CancellationToken.None);
                
            });

        }


    }
}
